//--------------------------------------------------------------------------------------------------------------
// <copyright file="CSPMyProperty.cs" company="Microsoft Corporation" author="David Martos" date="01/02/2008">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//--------------------------------------------------------------------------------------------------------------
using System;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.ComponentModel;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

using CSP.LoggingEngine;

namespace CSP.WebParts
{
    /// <summary>
    /// Civil servant cases
    /// </summary>
    [Guid("9C21FFAF-1696-432e-BA4B-4DBC991FE7A5")]
    public class CSPCivilServantMyCases : BaseWebPart
    {

        #region members
        protected Label errorLabel;
        protected int pageSize;
        protected bool openCaseInNewWindow = false;
        protected string caseDetailsURL = string.Empty;
        private const int PageSizeDefault = 10;
        private const bool OpenCaseInNewWindowDefault = true;
        private const string CaseDetailsURLDefault = "procedures/Pages/case_details.aspx";
        #endregion


        #region properties
        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [ResourcesAttribute("OpenCaseInNewWindowDisplayName", "CSPWebPartParameterCategory", "OpenCaseInNewWindowDescription")]
        [DefaultValue(OpenCaseInNewWindowDefault)]
        public bool OpenCaseInNewWindow
        {
            get { return this.openCaseInNewWindow; }
            set { this.openCaseInNewWindow = value; }
        }

        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [ResourcesAttribute("CaseDetailsURLDisplayName", "CSPWebPartParameterCategory", "CaseDetailsURLDescription")]
        [DefaultValue(CaseDetailsURLDefault)]
        public string CaseDetailsURL
        {
            get { return this.caseDetailsURL; }
            set { this.caseDetailsURL = value; }
        }

        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [ResourcesAttribute("DefaultPageSize", "CSPWebPartParameterCategory", "DefaultPageSizeDescription")]
        [DefaultValue(PageSizeDefault)]
        public int PageSize
        {
            get { return this.pageSize; }
            set { this.pageSize = value; }
        }
        #endregion

        #region methods
        /// <summary>
        /// Constructor
        /// </summary>
        public CSPCivilServantMyCases()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        /// <summary>
        /// Fired on page create child control, loads the ASCX file
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            try
            {

                UserControls.CSPCivilServantMyCasesWUC control = (UserControls.CSPCivilServantMyCasesWUC)Page.LoadControl(WebPartConstants.CSPCivilServantMyCasesWUC);
                control.WrapperWebPart = this;
                control.CaseDetailsURL = this.caseDetailsURL;
                control.OpenCaseInNewWindow = this.openCaseInNewWindow;               
                control.PageSize = this.pageSize;
                this.Controls.Add(control);

            }
            catch (CSP.Core.CSPException cspex)
            {
                errors.Add(this.LoadResource(WebPartConstants.CSPGenericErrorMessage));
            }
            catch (Exception ex)
            {
                this.LogMessage(this.LoadResource(WebPartConstants.CSPLoadControlErrorMessage), this.GetType().Name, ex);
                errors.Add(this.LoadResource(WebPartConstants.CSPGenericErrorMessage));
            }
        }
        #endregion
    }
}
